package com.itheima.service.impl;

import com.itheima.mapper.UserMapper;
import com.itheima.pojo.Emp;
import com.itheima.pojo.dao.UserDTO;
import com.itheima.pojo.vo.UserVo;
import com.itheima.service.UserService;
import com.itheima.utils.JwtUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public UserVo login(UserDTO userDTO) {
        Emp emp = userMapper.findUserByCheck(userDTO);
        UserVo userVo = new UserVo();
        BeanUtils.copyProperties(emp,userVo);
        Map<String, Object> claims = new HashMap<>();
        claims.put("USER_ID", emp.getId());
        String token = JwtUtil.createJWT("Nintendo_2024_9_26", 1000 * 60 * 60 * 24 * 7, claims);
        userVo.setToken(token);
        return userVo;
    }
}
